package com.example.model;

import java.io.Serializable;

import org.json.JSONObject;

import android.test.IsolatedContext;

public class OutProfile implements Comparable,Serializable{
	/*
	 * :{"id":"1", "username":"admin", "first_name":"", "last_name":"",
	 * "full_name":"Administrator", "email":"admin@admin.com", "is_active":"1",
	 * "properties":"", "active_code":""},
	 */
	private int id;
	
	private String id_device;
	private String id_contact;
	//persion
	private String _first_name ="";
	private String _last_name ="";
	private String _email ="";
	private String _mobile ="";
	private String _home_address  ="";
	private String _home_phone    ="";
	private String _birthday      ="";
	private int    _gender        = 0;
	//company
	private String _company_address ="";
	private String _company_phone ="";
	private String _company_website ="";
	private String _company_email   ="";
	private String _company_name="";
	
	private String getJson(JSONObject json,String propeties){
		String result  = "";
		try{
			result  = json.isNull(propeties)? "" : json.getString(propeties);
		}catch(Exception e){}
		return result;
		
	}
	
	public void setProperties(String properties) {
		
		try {
			JSONObject o = new JSONObject(properties);
			if (o.length() > 0) {
				_email           = getJson(o,"email") ;
				_first_name      = getJson(o,"first_name") ;
				_last_name       = getJson(o,"last_name") ;
				_gender          = Integer.parseInt(getJson(o,"gender"));
				_birthday        = getJson(o,"birthday") ;
				_mobile          = getJson(o,"mobile");
				_home_address    = getJson(o,"home_address") ;
				_home_phone      = getJson(o,"home_phone") ;
				
				_company_name    = getJson(o,"company_name") ;
				_company_website = getJson(o,"company_website") ;
				_company_email   = getJson(o,"company_email");
				_company_address = getJson(o,"company_address") ;
				_company_phone   = getJson(o,"company_phone") ;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}


	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}


	/**
	 * @return the _email
	 */
	public String get_email() {
		return _email;
	}
	/**
	 * @param _email the _email to set
	 */
	public void set_email(String _email) {
		this._email = _email;
	}
	/**
	 * @return the _password
	 */
	
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
    public void setId(String id){
    	try{
    		this.id  = Integer.parseInt(id);
    	}catch(Exception e){
    		this.id  = -1;
    	}
    }

	/**
	 * @return the id_device
	 */
	public String getId_device() {
		return id_device;
	}


	/**
	 * @param id_device the id_device to set
	 */
	public void setId_device(String id_device) {
		this.id_device = id_device;
	}


	/**
	 * @return the id_contact
	 */
	public String getId_contact() {
		return id_contact;
	}


	/**
	 * @param id_contact the id_contact to set
	 */
	public void setId_contact(String id_contact) {
		this.id_contact = id_contact;
	}


	


	
	
	
	/**
	 * @return the _first_name
	 */
	public String get_first_name() {
		return _first_name;
	}


	/**
	 * @param _first_name the _first_name to set
	 */
	public void set_first_name(String _first_name) {
		this._first_name = _first_name;
	}


	/**
	 * @return the _last_name
	 */
	public String get_last_name() {
		return _last_name;
	}


	/**
	 * @param _last_name the _last_name to set
	 */
	public void set_last_name(String _last_name) {
		this._last_name = _last_name;
	}


	


	/**
	 * @return the _home_address
	 */
	public String get_home_address() {
		return _home_address;
	}


	/**
	 * @param _home_address the _home_address to set
	 */
	public void set_home_address(String _home_address) {
		this._home_address = _home_address;
	}


	/**
	 * @return the _home_phone
	 */
	public String get_home_phone() {
		return _home_phone;
	}


	/**
	 * @param _home_phone the _home_phone to set
	 */
	public void set_home_phone(String _home_phone) {
		this._home_phone = _home_phone;
	}


	/**
	 * @return the _birthday
	 */
	public String get_birthday() {
		return _birthday;
	}


	/**
	 * @param _birthday the _birthday to set
	 */
	public void set_birthday(String _birthday) {
		this._birthday = _birthday;
	}


	/**
	 * @return the _gender
	 */
	public int get_gender() {
		return _gender;
	}


	/**
	 * @param _gender the _gender to set
	 */
	public void set_gender(int _gender) {
		this._gender = _gender;
	}
	public void set_gender(String _gender) {
		if(_gender != null && !_gender.equalsIgnoreCase("")){
			this._gender = Integer.parseInt(_gender);
		}else{
			this._gender = 0;
		}
		
	}

	/**
	 * @return the _company_address
	 */
	public String get_company_address() {
		return _company_address;
	}


	/**
	 * @param _company_address the _company_address to set
	 */
	public void set_company_address(String _company_address) {
		this._company_address = _company_address;
	}


	/**
	 * @return the _company_phone
	 */
	public String get_company_phone() {
		return _company_phone;
	}


	/**
	 * @param _company_phone the _company_phone to set
	 */
	public void set_company_phone(String _company_phone) {
		this._company_phone = _company_phone;
	}


	/**
	 * @return the _company_webiste
	 */
	public String get_company_website() {
		return _company_website;
	}


	/**
	 * @param _company_webiste the _company_webiste to set
	 */
	public void set_company_website(String _company_webiste) {
		this._company_website = _company_webiste;
	}


	/**
	 * @return the _company_name
	 */
	public String get_company_name() {
		return _company_name;
	}


	/**
	 * @param _company_name the _company_name to set
	 */
	public void set_company_name(String _company_name) {
		this._company_name = _company_name;
	}


	/**
	 * @return the _mobile
	 */
	public String get_mobile() {
		return _mobile;
	}
	/**
	 * @param _mobile the _mobile to set
	 */
	public void set_mobile(String _mobile) {
		this._mobile = _mobile;
	}
	
	
	/**
	 * @return the _company_email
	 */
	public String get_company_email() {
		return _company_email;
	}
	/**
	 * @param _company_email the _company_email to set
	 */
	public void set_company_email(String _company_email) {
		this._company_email = _company_email;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "OutProfile [id=" + id + ", id_device=" + id_device
				+ ", id_contact=" + id_contact + "\n, " 
				+ ", _email=" + _email         + "\n, "
				+ ", _first_name=" + _first_name + "\n, "
				+ ", _last_name=" + _last_name+ "\n, "
				+ ", _mobile=" + _mobile + "\n, "
				+ ", _home_address="+ _home_address + "\n, "
				+ ", _home_phone=" + _home_phone+ "\n, "
				+ ", _birthday=" + _birthday + "\n, "
				+ ", _gender=" + _gender+ "\n, "
				+ ", _company_address=" + _company_address+ "\n, "
				+ ", _company_phone=" + _company_phone + "\n, "
				+ ", _company_email=" + _company_email + "\n, "
				+ ", _company_website="+ _company_website + "\n, "
				+ ", _company_name=" + _company_name + "]";
	}
	@Override
	public int compareTo(Object another) {
		if(another instanceof OutProfile){
			OutProfile a = (OutProfile) another;
			if (id != a.getId()) return 1;
			if (!_email.equalsIgnoreCase(a.get_email())) return 1;
			if (!_first_name.equalsIgnoreCase(a.get_first_name())) return 1;
			if (!_last_name.equalsIgnoreCase(a.get_last_name())) return 1;
			if (!_mobile.equalsIgnoreCase(a.get_mobile())) return 1;
			if (!_home_address.equalsIgnoreCase(a.get_home_address())) return 1;
			if (!_home_phone.equalsIgnoreCase(a.get_home_phone())) return 1;
			
			
			if (!_birthday.equalsIgnoreCase(a.get_birthday())) return 1;
			if (_gender != a.get_gender()) return 1;
			
			
			if (!_company_address.equalsIgnoreCase(a.get_company_address())) return 1;
			if (!_company_email.equalsIgnoreCase(a.get_company_email())) return 1;
			if (!_company_name.equalsIgnoreCase(a.get_company_name())) return 1;
			if (!_company_phone.equalsIgnoreCase(a.get_company_phone())) return 1;
			if (!_company_website.equalsIgnoreCase(a.get_company_website())) return 1;
			
			return 0;
		}
		return 1;
		
		
	}
	
  
}